package com.danciyixue.boot.dcyx.controller;

import com.danciyixue.boot.dcyx.service.UserLoginInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.danciyixue.boot.dcyx.model.form.UserLoginInfoForm;
import com.danciyixue.boot.dcyx.model.query.UserLoginInfoQuery;
import com.danciyixue.boot.dcyx.model.vo.UserLoginInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.danciyixue.boot.common.result.PageResult;
import com.danciyixue.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 用户登录验证信息前端控制层
 *
 * @author youlaitech
 * @since 2025-06-15 16:37
 */
@Tag(name = "用户登录验证信息接口")
@RestController
@RequestMapping("/api/v1/user-login-info")
@RequiredArgsConstructor
public class UserLoginInfoController  {

    private final UserLoginInfoService userLoginInfoService;

    @Operation(summary = "用户登录验证信息分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('dcyx:user-login-info:query')")
    public PageResult<UserLoginInfoVO> getUserLoginInfoPage(UserLoginInfoQuery queryParams ) {
        IPage<UserLoginInfoVO> result = userLoginInfoService.getUserLoginInfoPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增用户登录验证信息")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('dcyx:user-login-info:add')")
    public Result<Void> saveUserLoginInfo(@RequestBody @Valid UserLoginInfoForm formData ) {
        boolean result = userLoginInfoService.saveUserLoginInfo(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取用户登录验证信息表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('dcyx:user-login-info:edit')")
    public Result<UserLoginInfoForm> getUserLoginInfoForm(
        @Parameter(description = "用户登录验证信息ID") @PathVariable Long id
    ) {
        UserLoginInfoForm formData = userLoginInfoService.getUserLoginInfoFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改用户登录验证信息")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('dcyx:user-login-info:edit')")
    public Result<Void> updateUserLoginInfo(
            @Parameter(description = "用户登录验证信息ID") @PathVariable Long id,
            @RequestBody @Validated UserLoginInfoForm formData
    ) {
        boolean result = userLoginInfoService.updateUserLoginInfo(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除用户登录验证信息")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('dcyx:user-login-info:delete')")
    public Result<Void> deleteUserLoginInfos(
        @Parameter(description = "用户登录验证信息ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = userLoginInfoService.deleteUserLoginInfos(ids);
        return Result.judge(result);
    }
}
